<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>发布预算询价</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="/res/css/respective/priceAsk/buyer.css" rel="stylesheet">
<link href="/res/third/city-picker/css/city-picker.css" rel="stylesheet">
	<style>
.backcontent .backfoot {
	padding-left: 0px;
} 
#attachfileName{
	margin-left: 0;
}
.city-picker-span{
	min-width: 215px;
    height: 32px;
    line-height: 31px;
    border: 1px solid #e9e9e9;
    padding-left: 15px;
    display: inline-block;
}
 
.toUpBill{
	color: #00b1db;position: absolute;right: 0;top:-50px;
}
.toUpBill:hover{
color: #1a8df3;}

#phoneTip span[role="alert"]{
    line-height: 19px;
}

#phoneTip span.n-icon{
    margin-top: 1.5px;
}
</style>
</head>
<body>
	[#include "/front/common/front_head.html"]
	<div class="warp" style="margin-top: 30px;"> 
		<div class="backcontent">
			<div class="back-main">
				<div class="mainContent" style="box-shadow:none;-moz-box-shadow:none;">
					<img src="/res/images/priceAsk/choseBill.png" alt=""
						style="width: 100%; margin-top: 47px;" />
					<div class="createOp">
						<h1>发布预算询价</h1>
						<form type="post" id="subform" autocomplete="off"
							data-validator-option="{theme:'yellow_right',timely:3, focusCleanup:true,stopOnError:true,focusInvalid:true}">
                            <input type="hidden" value="1" name="qtype" />
							[#--有清单, 则带表不需要清单,  无清单,则代表需要清单--]
							[#if hasdetail?? && hasdetail==1 ]
                                <input  type="hidden" value="0" name="needdesign" />
							[#else]
                                <input  type="hidden" value="1" name="needdesign" />
							[/#if]

							<div class="juZhong">
								<div style="padding: 35px 70px;background: white;">
							[#if !user??]
								<input type="hidden" name="temporary" value="true" />
								<div class="secTitle">
									<span>您还未登录，为了方便您发布询价，点击</span> <a href="javascript:login();">登录</a>/
                                    <a href="/user/register"  target="_blank">注册 </a>
								</div>
							[#else ]
								<input name="enqProject.customerId" value="${user.companyId!}" type="hidden" />
								<input name="enqProject.userId" value="${user.id}" type="hidden" />
								<input type="hidden" value="${user.id}" name="userId" />
                                <input type="hidden" value="${(enqmodel.id)!}" name="id"  />
							[/#if]


								<h2 class="thirdTitle">询价单名称</h2>
								<hr>
								<span>*</span>
								<input type="text" id="enquiryName" name="enquiryName"
                                       [#if editor??]
                                       readonly
                                       [/#if]
                                       style="width: 580px;"  data-rule="询价单名称:required;" value="${(enqmodel.enquiryName)!}" placeholder="请为该询价单写一个名称，方便您查阅。如：电缆询价第10单"/>



							[#if hasdetail == 1 ]
								<h2 class="thirdTitle">询价清单</h2>
								<hr>
								[#--无用字段,辅助验证用的 --]
                                <input id="excelvalid" type="hidden" value="[#if ((enqmodel.items)?? && enqmodel.items?size > 0 ) || (enqmodel.excelpath)?? ]1[#else]0[/#if]" name="excelvalid" />
                                <div id="upbefore" class="imgYalign"
								[#if ((enqmodel.items)?? && enqmodel.items?size > 0 )||(enqmodel.excelpath)?? ]
                                     style="display: none;"
								[/#if]
                                >
                                    <div>
                                        <h1>请上传询价清单</h1>
                                        <h2>建议使用Excel格式上传，方便系统为您更精准的推送给合适的供应商。</h2>
                                        <button type="button" onclick="uploadfile()" style="width: 125px;height: 30px;">上传清单</button>
                                        <a  href="/res/excel/询价模板.xls" target="_blank" >下载询价模板</a>
                                        <a onclick="addbyhand()">询价产品太少？点此手动填写</a>
                                    </div>
								</div>
								[#--有excelpath时 显示重新上传--]
								<div id="switchDiv" class="switchDiv"
								[#if !(enqmodel.excelpath)?? || (((enqmodel.items)??) && (enqmodel.items?size > 0)) ]
									 style="display: none"
								[/#if]
								>
								<a style="position: absolute;top:-50px;right: 0px;color: #00a8e6;" onclick="toHandOp()">询价产品太少？点此手动填写</a>
									<p style="font-size: 12px;">请在运营人员通过审核后查询匹配结果</p>
									<input type="hidden" name="excelpath" id="excelpath" value="${(enqmodel.excelpath)!}"   />
									<input type="hidden" name="excelName" id="excelName" value="${(enqmodel.excelName)!}" />
									
									<a id="filename" href="${(enqmodel.excelpath)!}" target="_blank">${(enqmodel.excelName)!}</a>
                                    &nbsp;&nbsp;<a id="delurl" onclick="delurl()">删除</a>
                                    <button class="reUp" type="button" onclick="uploadfile()">重新上传</button>
								</div>
				            <div style="position: relative;">
								<div id="upbyhand"
									[#if (!(enqmodel.items)??) || (enqmodel.items?size < 1) ]
										 style="display: none;"
									[/#if]
									>
									<a class="toUpBill" onclick="toUp()">询价产品很多？点此上传</a>  
				                    <table class="table noBorder smallTable" style="width: 100%;">
				                        <thead>
				                        <tr class="handHead">
				                            <th>所属系统</th>
				                            <th><dfn><span>*</span>商品名称</dfn></th>
				                            <th><dfn>品牌</dfn> </th>
				                            <th><dfn>型号</dfn></th>
				                            <th><dfn><span>*</span>单位 </dfn></th>
				                            <th><dfn><span>*</span>数量</dfn></th>
				                            <th><dfn>技术参数</dfn></th>
				                            <th><dfn>参考价</dfn></th>
				                            <th><a class="delAll" onclick="deleall(true)">全部删除</a></th>
				                        </tr>
				                        </thead>
				                        <tbody id="handBody">
				                        	[#if (enqmodel.items)?? && (enqmodel.items?size > 0 )]
                        					[#list enqmodel.items as item ]
				                            <tr attindex="${item_index}" >
				                                <td>
                                                    <button  class="choseOpButt" type="button"  onclick="chooseService(this)"     >
													[#--老数据导入没有第三级的id--]
													[#if item.categoryPId?? ]
														${item.categorySName!"选择系统"}
													[#else]
														选择系统
													[/#if]
													</button>
                                                    <input  type="hidden" value="${item.categorySId!}"  class="categorySId" name="items[${item_index}].categorySId" />
                                                    <input  type="hidden" value="${item.categoryPId!}" class="categoryPId" name="items[${item_index}].categoryPId" />
												 </td>
				                       			 <td>
				                                    <dfn id="delCont" style="position: relative;">
					                                    <input  type="text" novalidate name="items[${item_index}].productName" value="${item.productName}"  class="input_1 ainput" />
					                                	[#--<a class="delCont">×</a> --]
					                                </dfn>
				                                </td>
				                       			<td><dfn><input type="text"  novalidate name="items[${item_index}].brand"  value="${item.brand!}" class="ainput"/></dfn></td>
				                       			<td><dfn><input type="text"  novalidate name="items[${item_index}].model" value="${item.model!}" class="ainput" /></dfn></td>
				                                <td><dfn><input type="text"  novalidate name="items[${item_index}].unit"   value="${item.unit!}"  class="input_4 ainput" /></dfn></td>
				                                <td><dfn><input type="text"  novalidate name="items[${item_index}].quantity"  value="${item.quantity!}" class="input_5 ainput"  /></dfn></td>
				                                <td><dfn><input type="text"  novalidate name="items[${item_index}].descr" value="${item.descr!}" class="ainput" /></dfn></td>
												<td class="reference"></td>
				                                <td class="del" onclick="deletetr(this)" style="cursor: pointer;" ></td>
				                            </tr>
				                        [/#list]
				                        [#else ]
				                        <tr attindex="0" >
				                            <td>
                                                <button class="choseOpButt"  type="button"  onclick="chooseService(this)">选择系统</button>
												<input type="hidden" value="" name="items[0].categorySId" class="categorySId" />
												<input type="hidden" value="" name="items[0].categoryPId" class="categoryPId"  />
				                            </td>
				                            <td>
				                            	<dfn id="delCont" style="position: relative;">
					                                <input  type="text" novalidate name="items[0].productName" class="input_1 ainput" />
					                                [#--<a class="delCont">×</a> --]
				                                </dfn>
				                            </td>
				                            <td><dfn><input type="text"  novalidate name="items[0].brand" class="ainput"  /></dfn></td>
				                            <td><dfn><input type="text"  novalidate name="items[0].model"  class="ainput" /></dfn></td>
				                            <td><dfn><input type="text"  novalidate name="items[0].unit"     class="input_4 ainput" /></dfn></td>
				                            <td><dfn><input type="text"  novalidate name="items[0].quantity" class="input_5 ainput"  /></dfn></td>
				                            <td><dfn><input type="text"  novalidate name="items[0].descr" class="ainput"  /></dfn></td>
                                            <td class="reference"></td>
				                            <td class="del" onclick="deletetr(this)" style="cursor: pointer;" ></td>
				                        </tr>
				                        [/#if]
				                        </tbody>
				                        <tfoot>
				                        <tr class="tableBorde" style="background: none;">
				                            <td colspan="9" style="text-align: right;padding:15px;">
				                                <button  onclick="additem()"  type="button" class="addProduc">新增产品</button>
				                            </td>
				                        </tr>
				                        </tfoot>
				                    </table>
				                </div>
                            </div>


							[/#if]

				                <h2 class="thirdTitle">询价要求</h2>
				                <hr>
				                <div class="lableIterm">
					                <label><span>*</span>报价截止时间：</label>
					                <input  id="endtime" value="${(enqmodel.deadline?string("yyyy-MM-dd"))!}" name="deadline" data-rule="截止时间:required;"  type="text" class="clock"/>
					            </div>
					            <div class="lableIterm">
					                <label><span>*</span>质保要求：</label>
					                <input style="margin-left: 0;" type="radio" name="quality" value="1"  [#if !enqmodel??]checked="checked"[/#if] [#if (enqmodel.quality)?? && enqmodel.quality==1 ] checked="checked" [/#if]>1年

					                <input type="radio" name="quality" value="2" [#if (enqmodel.quality)?? && enqmodel.quality==2 ] checked="checked" [/#if]>2年


					                <input type="radio" name="quality" value="3" [#if (enqmodel.quality)?? && enqmodel.quality==3 ] checked="checked" [/#if]>3年


					                 <input type="radio" name="quality" value="15" [#if (enqmodel.quality)?? && enqmodel.quality==15 ] checked="checked" [/#if]>15年


					                 <input type="radio" name="quality" value="-1"
											[#if (enqmodel.guaranteeinfo)?? && (  (!enqmodel.quality??) || (enqmodel.quality?? && enqmodel.quality==-1))  ]checked="checked" [/#if]
									 >其他
					                 <input  name="guaranteeinfo" id="guaranteeinfo" value="[#if (enqmodel.guaranteeinfo)??  ]${enqmodel.guaranteeinfo!}[/#if]"  type="text" style="width: 80px;height: 20px;margin-left: 15px;
									 [#--有特殊质保要求时,该input显示--]
									 [#if (enqmodel.guaranteeinfo)?? && (  (!enqmodel.quality??) || (enqmodel.quality?? && enqmodel.quality==-1))  ][#else]display:none;[/#if]" />
					            </div>
					            <div class="lableIterm">
					                <label>报价要求：</label>
					                <input type="checkbox"  name="taxPrice" id="taxPrice" value="1"
					                    [#if (enqmodel.taxPrice)?? && enqmodel.taxPrice!=3 ]
					                        checked="checked"
					                    [/#if]
					                    >包含税价
					                <div class="ppSelect dealSelec" id="taxInstro"
									[#if (enqmodel.taxPrice)?? && enqmodel.taxPrice!=3 ]
									[#else]
                                         style="display: none;"
									[/#if]
									>
										[@m.select  name="taxInstro" options={"3":"3%","6":"6%","17":"17%"} val=((enqmodel.taxInstro)!17)?string  attr="style='height: 100%; border: none;'"  /]

					                </div>

					                <label style="width: auto;">
					                    <input type="checkbox" value="1" name="shipPrice" style="margin-left: 10px;"
					                    [#if  (enqmodel.shipPrice)?? && enqmodel.shipPrice==1]
					                    checked="checked"
					                    [/#if]
					                    >包含运费价
					                </label>
            					</div>
            					 <div class="lableIterm">
					                <label >需供应商提供：</label>
									 [@m.checkbox  name="providefiles"  checked=(enqmodel.hasprovide(1))!false  value="1"   /]解决方案
									 [@m.checkbox  name="providefiles"  checked=(enqmodel.hasprovide(2))!false  value="2"  /]拓扑图
					            </div>


					            <div class="lableIterm">
					                <label><span>*</span>项目资料：</label>
					               [#--附件结果--]
					                <input   type="hidden" name="attachfile" id="attachfile"
					                       value="${(enqmodel.attachfile)!}"
					                />
					                <input   type="hidden" name="attachfileName" id="attachfileName"
					                       value="${(enqmodel.attachfileName)!}"
					                />

					                <small id="uploadattach" class="col-xs-8"
					                [#if (enqmodel.attachfile)?? && enqmodel.attachfile!="" ]
					                     style="display: none"
					                [/#if]
					                >
					                    <img alt="" src="/res/images/priceAsk/ask04.png" style="vertical-align: middle;"/>
					                    <a id="fileUpload" style="font-size: 14px;vertical-align: middle;"
					                       onclick="uploadEnclosure()"
					                    >资料打包后上传</a>
					                </small>
					                <small id="uploadattachfile" class="switchDiv col-xs-8"
					                [#if !((enqmodel.attachfile)?? && enqmodel.attachfile!="") ]
					                     style="display: none;"
					                [/#if]
					                >
					                    <a id="attachfileNameTip" target="_blank"  href="${(enqmodel.attachfile)!}"   >[#if enqmodel?? && enqmodel.attachfileName?? ]${(enqmodel.attachfileName)!}[#else]${(enqmodel.attachfile)!}[/#if]</a>
                                        &nbsp;&nbsp;<a   onclick="delattachurl()"  style="color: #00a8e6;">删除</a>
                                        <button class="reUp" type="button" onclick="uploadEnclosure()">重新上传</button>
					                </small>
					            </div>

                                <div class="lableIterm">
                                    <label>补充说明：</label>
                                    <textarea style="vertical-align: top;" name="otherRemarks" rows="5" cols="95" class="form-control" >${(enqmodel.otherRemarks)!}</textarea>
                                </div>

					            <h2 class="thirdTitle">项目信息</h2>
					            <div class="lableIterm">
					                <label ><span>*</span>项目名称：</label>

					                 [#if editor?? ]
					                    <input name="projectId" value="${enqmodel.projectId}" type="hidden" >
					                [#else]
					                	[#--编辑状态不用显示项目名称输入框--]
					                    <input  id="choosenew"  name="enqProject.projectName"  value="${(enqmodel.enqProject.projectName)!}"    type="text" class="form-control" placeholder="供应商能查看，建议输入内容不包含甲方名称。如：某净化工程项目"/>
					                [/#if]

					                [#--选择已经有的之后,这里显示选择的项目名称--]
					                [#if editor?? ]
					                    <a id="chhoseold" style="color: black;" >${enqmodel.enqProject.projectName}</a>
					                [#else]
					                    <a id="chhoseold" style="color: black;display: none;" ></a>
					                [/#if]


					                [#if !editor?? ]
					                [#--编辑状态,不显示该按钮--]
					                    <a  id="createnew" style="color: black;display: none" >创建新的?</a>
					                [/#if]

					                [#if projects??]
					                	<div  class="ppSelect" style="width: auto;">
					                		<select  id="choosehistory" name="projectId" style="width: auto;padding: 0 18px;" >
						                        <option value="0" selected="selected" >选择已有</option>
						                      [#list projects as proj]
						                          <option  value="${proj.id!}"
						                                   attcnam="${proj.customerName!}"
						                                   attprov="${proj.areaProvince!}"
						                                   attprovn="${proj.provinceName!}"
						                                   attcity="${proj.areaCity!}"
						                                   attcityn="${proj.cityName!}"
						                          >
						                          ${proj.projectName!}
						                          </option>
						                      [/#list]
						                    </select>
					                	</div>
					                [#else]
										[#if !editor?? ]
					                    <input type="hidden" value=0 id="choosehistory" />
										[/#if]
					                [/#if]

					            </div>
            					<div class="lableIterm">
					                <label >甲方名称：</label>

					                    <input id="customerName" name="enqProject.customerName"
					                           [#if editor?? ]
					                              [#--编辑模式,该项不能改--]
					                            readonly="readonly"
					                           [/#if]
					                           value="${(enqmodel.enqProject.customerName)!}"  type="text" class="form-control" placeholder="只有您自己能查看，方便您后续查询项目及订单"/>

					            </div>
					             <div id="areawrap" class="lableIterm">
					                <label ><span>*</span>项目所在地：</label>

					                    <input id="areacode" name="enqProject.areaProvince" value="${(enqmodel.enqProject.areaProvince)!}"    type="hidden"/>
					                    <input  id="areaname" name="enqProject.provinceName"  value="${(enqmodel.enqProject.provinceName)!}" type="hidden" />

					                    <input id="citycode"  name="enqProject.areaCity" value="${(enqmodel.enqProject.areaCity)!}"  type="hidden" >
					                    <input id="cityname"  name="enqProject.cityName"  value="${(enqmodel.enqProject.cityName)!}" type="hidden" >

					                    <input  id="areaProvince" value="${(enqmodel.enqProject.provinceName)!}[#if (enqmodel.enqProject.cityName)??]/${(enqmodel.enqProject.cityName)!}[/#if]" type="text"  placeholder="请选择省/市" class="form-control"  readonly />

					            </div>
					            <div class="lableIterm">
					                	<label><span>*</span>联系人：</label> 
					                    <input  data-rule="required;"  name="contacts"
					                            [#if editor?? ]
					                            [#--编辑模式,取的地方不同--]
					                            value="${(enqmodel.contacts)!}"
					                            [#else]
					                                [#if (enqmodel.contacts)??]
					                                value="${(enqmodel.contacts)!}"
					                                [#else ]
					                                value="${(user.realName)!}"
					                                [/#if]
					                            [/#if]
					                            type="text" class="form-control" placeholder="请填写项目联系人" />

					            </div>
								[#if user?? ]
									<div class="lableIterm">
										<label><span>*</span>联系电话：</label>
											<input id="myphone" name="phone" type="text" class="form-control contact" readonly
										[#if user.mobile?? && user.mobile!="" ]
												   value="${user.mobile!0}"
										onclick="tipShow()" onblur="tipHide()"/>
										[#else]
											style="display: none;"
											/>
											<a  id="bindphone" onclick="bindPhone()" >请先绑定手机号</a>
										[/#if]
										<span id="phoneTip" style="display: inline-block;text-align: left;"></span>
									</div>
								[/#if]
					            <div class="lableIterm">
					                <label >QQ：</label>

					                    <input  name="qq" type="text" class="form-control" placeholder="请填写QQ号码"
					                        value="${(enqmodel.qq)!}"
					                    />

					            </div>
					             <div class="lableIterm">
					                <label >E-mail：</label>

					                    <input  data-rule="邮箱:email;"   name="email"
					                    [#if editor?? ]
					                    [#--编辑模式,取的地方不同--]
					                            value="${(enqmodel.email)!}"
					                    [#else]
					                            value="${(user.email)!}"
					                    [/#if]
					                             type="text" class="form-control contact" placeholder="请填写邮箱地址"/>

					            </div>
								</div>
							</div>
						</form>
                        <div class="confirmForm">
                            <button id="subtn" type="button" onclick="subform([#if editor??]true[#else]false[/#if])">确认发布</button>
                        	<button id="backButt" type="button" onclick="window.history.back()">返回</button>
                        </div>
					[#if !editor?? ]
						[@rule_content code="publish_budget"/]   
					[/#if]
					</div>
				</div>
			</div> 
		</div> 
	</div> 
	<div   id="successresult" class="faBuSuc"   >
		<div class="contTip"><img style="height: 40px;" src="/res/images/oparaStatus/aliveSuc_03.jpg" alt="">
			<div style="display: inline-block;vertical-align: top;margin-left:10px;"><h5>询价单提交成功</h5><h6 style="margin:10px 0 5px 0;">您发布的询价已提交，我们将在一个工作日内为您</h6><h6>
                完成审核，如比较紧急请致电：<strong style="color:#f9a32a;">400 848 1365</strong></h6><h6 style="margin-top: 10px;">您还可以 <a id="detailenq">查看刚发布的询价单</a> | <a id="managerenq" >管理询价单</a> | <a href="/enquiry/design/choose/" >继续发布询价单</a></h6></div>
		</div>
		<div style="text-align: center;margin-top: 30px;">
			<button class="iKnow" type="button" onclick="location.href=$('#detailenq').attr('href')">我知道了</button>
		</div>
	</div>


    <div style="width: 550px;bottom: 300px;background: white;z-index: 105;width: 570px;display:none;" id="toHand">
        <div style="margin-top: 50px;">
            <img alt="" src="/res/images/oparaStatus/warn.jpg" style="float: left;margin-left: 25px;">
            <h3 style="font-size: 18px;font-weight: bold;color: #333;margin: 0px;">您已经上传了清单文件</h3>
            <h6 style="font-size: 14px;color: #666;margin: 5px auto;margin-bottom: 0px;">切换到手动填写，您已经上传的询价清单将被清除，确认使用手工填写吗？</h6>
            <div style="width: 500px;margin-left:30px;margin-top: 30px;">
                <hr style="border: 1px solid #dddddd;">
                <h6 style="margin-top: 25px;width: 600px;">
                    <strong style="color:#00ccff;">温馨提示：</strong>如果上传的清单缺少需要询价的产品，请在原清单中添加缺少的产品后，重新上传。
                </h6>
            </div>
            <div style="margin-top: 30px;text-align: center;margin-bottom: 20px;">
                <button style="width: 95px;height: 35px;background: #00ccff;font-size: 16px;color: white;cursor: pointer;border: 1px solid #00ccff;margin-right: 20px;" onclick="toHandOp2(1)">确定</button>
                <button style="width: 95px;height: 35px;border: 1px solid #00ccff;font-size: 16px;color: #00ccff;cursor: pointer;background: white;" onclick="toHandOp2(0)">取消</button>
            </div>
        </div>
    </div>

    <div style="width: 530px;bottom: 300px;background: white;display:none;" id="toUp">
        <div style="margin-top: 50px;">
            <img alt="" src="/res/images/oparaStatus/warn.jpg" style="float: left;margin-left: 25px;">
            <h3 style="font-size: 18px;font-weight: bold;color: #333;margin: 0px;">您已经填写了询价清单</h3>
            <h6 style="font-size: 14px;color: #666;margin: 5px auto;margin-bottom: 0px;">切换到清单上传，您已手工填写的产品将被清除，确定使用清单上传吗?</h6>

            <div style="margin-top: 45px;text-align: center;margin-bottom: 20px;">
                <button style="width: 95px;height: 35px;background: #00ccff;font-size: 16px;color: white;cursor: pointer;border: 1px solid #00ccff;margin-right: 20px;" onclick="toUp2(1)">确定</button>
                <button style="width: 95px;height: 35px;border: 1px solid #00ccff;font-size: 16px;color: #00ccff;cursor: pointer;background: white;" onclick="toUp2(0)">取消</button>
            </div>
        </div>
    </div>

<script src="/res/js/common/common.js"></script>
<script src="/res/third/laydate/laydate.js"></script>
<script src="/res/third/layer/layer.js"></script>
<script src="/res/third/layer/layer.extends.js"></script>
<script src="/res/third/nice-validator/jquery.validator.min.js?local=zh-CN"></script>
<script src="/res/third/city-picker/js/city-picker.data.js"></script>
<script src="/res/third/city-picker/js/city-picker.js"></script>
<style>
    .n-default .n-left, .n-default .n-right{
        margin-top:7px;
    }
    #phoneTip .n-right{
        margin-top:0px;
    }
</style>
<script type="text/javascript">
[#if hasdetail==1]

    function refrerence(obj,v,fn) {
        obj.html('<img src="/res/third/layer/skin/default/loading-1.gif"  style="width:20px;height: 20px;" />');
        $.getJSON("/enquiry/reference",{name:v},function(data){
            if(fn)fn();
            if(data.success){
                var min = data.attributes.min;
                var max = data.attributes.max;
                if(min==max){
                    obj.html($.my.currency(min,true));
                }else{
                    obj.html($.my.currency(min,true)+"~"+$.my.currency(max,true));
                }
            }else{
                obj.html("");
            }
        });
    }
	$("body").on("blur","input[name$='productName']",function () {
        var obj = $(this).parents("tr").find("td").eq(7);
		var v = $(this).val();
		if(v.trim()!=""){
            refrerence(obj,v);
		}
    });
    [#if editor??]
        function prodctNameBlur(i,max) {
            console.log(i+"~"+max);
            if(i<max){
                var productNameObj = $("input[name$='productName']").eq(i);
                var refrerenceObj = productNameObj.parents("tr").find("td").eq(7);
                refrerence(refrerenceObj,productNameObj.val(),function () {
                    prodctNameBlur(++i,max);
                });
            }
        }

        [#--编辑的时候,自动计算参考价--]
        var size = $("input[name$='productName']").size();
        prodctNameBlur(0,size);
    [/#if]
[/#if]

function cityreset() {
    $("#areaProvince").citypicker({level:"city",simple:true,feedValBack:function (v) {
        $("#areaname").parent().find(".msg-box").remove();
    }});
}
[#if !(editor??) ]
		cityreset();
[/#if]

$(function(){
	$("#delCont").hover(function(){
		$(this).children("a").show();
	},
	function(){
		$(this).children("a").hide();
	});
})
/*上传区别对待*/
[#--上传--]  [#--重传--]
    function uploadfile(){
        layer.fileManager(
                {initType:"file",
                suffixTypes:"xls,xlsx",
				fileSingleSizeLimit:5242880*2,
                "callback":function(data){
                upcallback(data);
                }}
        );
    }
    function uploadEnclosure(){
        layer.fileManager(
            {	initType:"file",
                suffixTypes:"doc,docx,xls,xlsx,ppt,pptx,zip,rar,gif,jpg,jpeg,bmp,png,pdf",
                fileSingleSizeLimit:5242880*2,
				"callback":function(data){
                attachfileback(data);
            	}
            }
        );
    }

//验证并且预先处理
$("#subform").validator({
    theme:"yellow_right",
    timely:2,
    focusCleanup:true,
    stopOnError:true,
    focusInvalid:true,
    rules:{
        v_excel:function (el, param, field) {
            if($("#upbefore").is(":visible")){
                layer.msgShort("请上传询价清单");
                window.scrollTo(0,100);
                return "请上传询价单";
            }else{
                var excelpath = $("#excelpath").val();
                var itemvisible = $("#upbyhand").is(":visible");
                if(excelpath==null || excelpath =="" || itemvisible ){//手动上架
                    var flag = true;
                    $(".input_1").each(function(){
                        var v = $(this).val().trim();
                        if(v==""){
                            layer.msgShort("商品名称不能为空!");
                            flag=false;
                            return false;
                        }
                    });

                    if(flag){
                        $(".input_4").each(function(){
                            var v = $(this).val().trim();
                            if(v==""){
                                layer.msgShort("单位不能为空!");
                                flag=false;
                                return false;
                            }
                        });
                    }

                    if(flag){
                        $(".input_5").each(function(){
                            var v = $(this).val().trim();
                            var re =/^[0-9]+.?[0-9]*$/;
                            if(!re.test(v)){
                                layer.msgShort("数量必填且必须为数字!");
                                flag=false;
                                return false;
                            }
                        });
                    }
                    if(flag){
						$(".categorySId").each(function () {
							var v  = $(this).val();
							if(v==""){
                                layer.msgShort("请选择系统");
								flag=false;
								return false;
							}
                        });

						$(".categoryPId").each(function () {
							var v  = $(this).val();
							if(v==""){
                                layer.msgShort("请选择系统");
								flag=false;
								return false;
							}
                        })
					}


                    if(!flag){
                        window.scrollTo(0,100);
                        return "询价单填写不完整"
                    }
                    return true;

                }
            }
        },
        v_city:function() {
			[#--项目所在地 ,选择已经有的项目就不需要判断了--]
            if($("#choosehistory").val()==0){
                var data = $("#areaProvince").data("citypicker");
                $("#areacode").val("");
                $("#areaname").val("");
                $("#citycode").val("");
                $("#cityname").val("");

                var getcode = data.getCode().trim();
                if(getcode==""){
                    layer.msgShort("请选择项目所在地");
                    var top = $("#areawrap").offset().top;
                    window.scrollTo(0,top);
                    return "请选择项目所在地";
                }else{
                    var text = data.getVal();
                    if(getcode.indexOf("/")!=-1){
                        var codes = getcode.split("/");
                        var names = text.split("/");

                        $("#areacode").val(codes[0]);
                        $("#areaname").val(names[0]);

                        $("#citycode").val(codes[1]);
                        $("#cityname").val(names[1]);

                    }else{
                        $("#areacode").val(getcode);
                        $("#areaname").val(text);
                    }

                }
            }
            return true;
        },
        v_attachfile:function () {
			var v = $("#attachfile").val();
			if(v.trim()==""){
                var top = $("#uploadattach").offset().top-250;
                window.scrollTo(0,top);
                layer.msgShort("项目资料必须上传");
                return "项目资料必须上传";
			}
			return true;
        },
        v_phone:function (el, param, field) {
            var isPhone = /^([0-9]{3,4}[-_－—]?)?[0-9]{7,8}$/;
//            var isMob=/^((\+?86)|(\(\+86\)))?(13[012356789][0-9]{8}|15[012356789][0-9]{8}|18[02356789][0-9]{8}|147[0-9]{8}|1349[0-9]{7})$/;
            var value=$("#myphone").val().trim();
            if(isPhone.test(value)){
                return true;
            }else{
                return "请先绑定手机号";
            }
        },
        v_ismyproject:function(el, param, field){
            var projectname =field.value;
            var msg =true;
            $.ajax({
                type:"post",
                url:"/enquiry/project/ismy",
                data:{projectname:projectname},
                dataType:"json",
                async:false,
                success:function(data){
                    if(!data.success){
                        msg=data.msg;
                    }
                }
            });

            return msg;
        }
    },
    fields: {
        enquiryName:"询价单名称:required;",
        excelvalid:{
            rule:"请上传询价单:required;v_excel; ",
            target:"#upbefore"
        },
        attachfile:{
            must:true,
        	rule:"v_attachfile;",
			target:"#fileUpload"
		},
        "enqProject.projectName":{
            //2017.1.16 不能与自己发的项目重名
            rule:"项目名称:required;v_ismyproject;",
            target:"#choosehistory"
        },
        "enqProject.provinceName":{
            rule:"v_city;",
            target:"#areawrap",
            must:true
        },
        phone:{
            must:true,
            target:"#phoneTip",
            rule:"v_phone;"
        }
    }
});



	[#--截止时间--]
    laydate({
        elem: '#endtime',
        min: laydate.now(),
        choose:function () {
            $("#endtime").focus();
        }
    });

	$("#handBody").on("mouseover mouseout",".del , .delActive" ,function(event){
        if(event.type == "mouseover"){
            $(this).removeClass("del").addClass("delActive");
        }else if(event.type == "mouseout"){
            $(this).removeClass("delActive").addClass("del");
        }
    });




    [#--上传回调--]
    function upcallback(response,params){
        if(response instanceof Array){
            response =response[0];
        }
        layer.closeAll();
        layer.msgShort("上传成功");
        var url = response.url;
        var name = response.name;
        $("#filename").html(name);
        $("#filename").attr("href",url);

        $("#excelName").val(name);
        chagestat(true,url);
    }
    [#--删除上传的--]
    function delurl(){
        chagestat(false,null);
    }


    [#--手动添加--]
    function addbyhand(){
		$("#upbyhand").show();
		$("#upbefore").hide();
	}

	/*删除所有*/
	function deleall(haswarn){
        var flag = checkShuru();
        if(flag && haswarn){
            layer.alert("确定全部删除?",function(){
                dealAllOk();
                layer.closeAll();
            })
        }else{
            dealAllOk();
        }
	}
	/*确认全部删除*/
	function dealAllOk(){
		$("#upbyhand").hide();
		$("#upbefore").show();

		var size = $(".del").size();
		for(var i=size-1;i>=0;i--){
			removeTr($(".del").eq(i));
		}
	}

function chagestat(b,url){
		if(b){
			$("#switchDiv").show();
			$("#upbefore").hide();
            $("#excelpath").val(url);
		}else{
            $("#switchDiv").hide();
            $("#upbefore").show();
            $("#excelpath").val("");
		}
	}

	[#--添加行--]
	function additem(){
        var ctr = $("#handBody").find("tr").last().clone(true);
        var indexnum = parseInt(ctr.attr("attindex"))+1;
        ctr.attr("attindex",indexnum);

        //序号
        ctr.find("td").eq(0).find("span").eq(0).text(indexnum+1);
        var ctrhtml = ctr.html();

        var abc = ctrhtml.replace(/items\[(\d+)\]/gm,"items["+indexnum+"]");
		//重置tr里的内容
        ctr.html(abc);

        ctr.find("input[class^='input_']").val("");
		ctr.find("td").eq(7).html("");
        $("#handBody").append(ctr);
	}


    //删除行
    function deletetr(obj){
        //询问框
        layer.confirm('是否清除该行？',function(){
            removeTr(obj);
            layer.msgShort("已清除");
        });
    }

    function removeTr(obj){
        var l = $("#handBody").find("tr").length;
        var _this = $(obj);
        var _parent = _this.parents("tr");
        if(l==1){
            _parent.find("input").each(function(i){
                if(i>1){
                    $(this).val("");
                }
            })
        }else {
            var indexnum = parseInt(_parent.attr("attindex"));
            _parent.nextAll().each(function(){
                $(this).attr("attindex",indexnum);
                $(this).find("td").eq(0).find("span").eq(0).text(indexnum+1);
                $(this).html($(this).html().replace(/items\[(\d+)\]/gm,"items["+indexnum+"]"));
                indexnum++;
            });
            _parent.remove();
        }
    }

    [#--报价要求：--]
    $("#taxPrice").click(function(){
        if($(this).is(":checked")){
            $("#taxInstro").show();
        }else{
            $("#taxInstro").hide();
        }
    });

    [#--质保要求 其他--]
    $("input[name='quality']").click(function(){
        if($(this).val()==-1){
            $("#guaranteeinfo").show();
        }else {
            $("#guaranteeinfo").hide();
        }
    });


    [#--上传附件回调--]
    function attachfileback(response,params){
        if(response instanceof Array){
            response =response[0];
        }
        layer.closeAll();
        layer.msgShort("上传成功");
        var url = response.url;
        var name = response.name;
        $("#attachfile").val(url);
        $("#attachfileName").val(name);
        $("#attachfileNameTip").html(name);
        $("#attachfileNameTip").attr("href",url);
        $("#uploadattach").hide();
        $("#uploadattachfile").show()
        $("#attachfile").focus();
    }

    [#--删除附件--]
    function delattachurl(){
        $("#uploadattach").show();
        $("#uploadattachfile").hide();
        $("#attachfile").val("");
        $("#attachfileName").val("");
    }

function subform(iseditor){
        if($("#subform").isValid()){
            var flag = true;
            if(flag){
                layer.post({
                    url:"/enquiry/purchase/create/save",
                    data:$("#subform").serialize(),
                    success:function(data){
                        if(data.success){
                            if(data.obj){
                                login();
                            }else{
                            	var enqid = data.msg;
                                var ids = enqid.split("-");
								$("#detailenq").attr("href","/enquiry/purchase/detail/"+ids[0]);
								$("#managerenq").attr("href","/enquiry/project/detail/p/"+ids[1]+"/t/1");

                                layer.open({
                                    type: 1,
                                    title: false, //不显示标题
                                    maxWidth:500,
                                    content: $("#successresult"),
                                    cancel:function () {
                                        location.reload();
                                    }
                                });

                            }

                        }else{
                        	layer.msgShort(data.msg);
						}
                    }
                },"保存中");
            }

        }
    }




    [#--选择已经有的--]
    $("#choosehistory").change(function(){
        if($(this).val()!=0){
            $("#choosenew").attr("novalidate",true).focus();
            $("#choosenew").hide();
            var opt = $(this).find("option:selected");
            $("#chhoseold").html(opt.text()).show();
            /*甲方名称*/
            var attcnam = opt.attr("attcnam");
            $("#customerName").val(attcnam).attr("readonly","readonly");
            /*项目所在地*/
            var attprovn = opt.attr("attprovn");
            var attcityn = opt.attr("attcityn");
			if(attcityn==""){
                $("#areaProvince").val(attprovn);
            }else{
                $("#areaProvince").val(attprovn+"/"+attcityn);
			}


            $("#areaProvince").citypicker('destroy');
            $("#createnew").show();
            $(this).parent().hide();
        };
    });

	/*创建该项目下的询价*/
	[#if projectId?? ]
	$("#choosehistory").val(${projectId}).change();
	$("#enquiryName").focus();
[/#if]
    [#--创建新的项目--]
    $("#createnew").click(function(){
        //$("#areaProvince").citypicker('reset');
		cityreset();
        $(this).hide();
        $("#customerName").val("").removeAttr("readonly");
        $("#chhoseold").html("").hide();
        $("#choosenew").val("").show().removeAttr("novalidate");
        $("#choosehistory").val(0).parent().show();
    });


    function login(){
        layer.login("loginback");
    }
    function loginback(){
        location.reload();
    }


	//选择器
    var  $checkedobj =null;
	function chooseService(obj){
        $checkedobj =$(obj);
		var current =$checkedobj.next().next().val();
        layer.category("/category/choose",{callback:"callback",current:current},obj);
    }

	function callback(name,id,atttop) {
		layer.closeAll();
        $checkedobj.text(name);
        $checkedobj.next().val(atttop).next().val(id);

    }


/*判断有没有输入内容*/
function checkShuru(){
    var flag = false;
    var l = $(".ainput").each(function () {
        var v = $(this).val();
        if(v!=""){
            flag=true;
            return false;
        }
    });
    return flag;
}
/*手动切换到上传**/
function toUp(){
    var flag = checkShuru();
    if(flag){
        layer.open({
            type:1,
            title:false,
            area: ['530px', '253px'], //宽高
            content:$("#toUp")
        })
    }else{
    	//清空
        toUp2(1)
    }
}
function toUp2(type) {
    layer.closeAll();
    if(type==1){
        deleall(false);
    }
}


//切换手动
function toHandOp(){
    layer.open({
        type:1,
        title:false,
        area: ['635px', '293px'], //宽高
        content:$("#toHand")
    })
}
function toHandOp2(type) {
    layer.closeAll();
    if(type==1){
        $("#switchDiv").hide();
        $("#upbyhand").show();
    }
}


function bindPhone(){
    layer.bindPhone("bindcallback");
}
function bindcallback(mobile) {
    $("#myphone").val(mobile).show();
    $("#bindphone").hide();
    $("#phoneTip").empty();
    layer.closeAll();
}
function tipShow(){
	$("#phoneTip").text("抱歉，联系电话不可更改");
	$("#phoneTip").show();
}
function tipHide(){
	$("#phoneTip").text("");
	$("#phoneTip").hide();
}
</script>
[#include "/front/common/front_foot.html"]
</body>
</html>
